package com.hyzh.latte.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.hyzh.latte.vehicle.dmo.entity.PolePGEntity;
import com.hyzh.latte.vehicle.dmo.entity.PolePointPGEntity;

import java.io.*;
import java.util.List;

/**
 * @author songkui
 * @since 2024/4/23 9:30
 */
public class JsonUtil {
    //读取json文件
    public static String readJsonFile(String fileName) {
        String jsonStr = "";
        try {
            File jsonFile = new File(fileName);
            FileReader fileReader = new FileReader(jsonFile);
            Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {

//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        LocalDateTime startDateTime = LocalDateTime.parse("2024-04-01 00:00:00", formatter);
//        LocalDateTime endDateTime = LocalDateTime.parse("2024-04-11 00:00:00", formatter);
//        long days = startDateTime.until(endDateTime, ChronoUnit.DAYS);
//        System.out.println("-----------------------------" + days);

        String path = JsonUtil.class.getClassLoader().getResource("pole_point.json").getPath();
        String s = readJsonFile(path);
      List<PolePointPGEntity> map = JSON.parseObject(s, new TypeReference<List<PolePointPGEntity>>(){});
        System.out.println(map.size());
    }

}
